home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 10828 / 10828.xpi / chrome / content / newTabKingOverlay-min.js < prev    next >
Text File  |  2010-02-07  |  33KB  |  764 lines

  1. const STATE_START=Components.interfaces.nsIWebProgressListener.STATE_START;
  2. const STATE_STOP=Components.interfaces.nsIWebProgressListener.STATE_STOP;
  3. var NewTabKing={
  4.     version:"3.1.3",
  5.     customAdSenseChannel:false,
  6.     adSenseChannel:"partner-pub-0262891402493658:mqkypu-b0gi",
  7.     partnerName:'ntk-partner',
  8.     MY_ID:"{FC5BAC7D-D696-4ba6-B913-CF8F000C33DF}",
  9.     isFirefox3:false,
  10.     ntkWindowOn:false,
  11.     ntkWindow:null,
  12.     ntkTabPerfOn:true,
  13.     prefs:null,
  14.     recentTabsArr: new Array(),
  15.     proactiveNTKClose:false,
  16. maxRecentTabsOpt:8,ss:null,em:null,historyService:null,thumbnailsRefreshHrs:12,loaderBox:null,loaderBrowser:null,globalTab:null,globalActiveTab:null,refreshEveryXTabs:40,mystrings:Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService).createBundle("chrome://newtabking/locale/newtabking.properties"),
  17. getUsageCnt:function(){return NewTabKing.prefs.getIntPref("usageCnt")},
  18. setUsageCnt:function(a){NewTabKing.prefs.setIntPref("usageCnt",a)},
  19.  
  20. SettingChange:function(a){
  21.     if (NewTabKing.ntkTabPerfOn) { setTimeout("NewTabKing.initNTKPage(-1);",200); }
  22.     setTimeout("NewTabKing.TabSelected(1);",777);
  23. },
  24.  
  25. replaceBrowser: function () {
  26.         var c, d, i;
  27.         var b = document.createElement("hbox");
  28.         b.setAttribute("id", "ntkLoaderBox");
  29.         b.setAttribute("style", "overflow: hidden; visibility: hidden;");
  30.         b.setAttribute("flex", "1");
  31.         b.setAttribute("height", "0");
  32.         b.setAttribute("maxheight", "0");
  33.         b.setAttribute("minheight", "0");
  34.         var e = document.createElement("vbox");
  35.         e.setAttribute("id", "ntkLoaderSubBox");
  36. //        e.setAttribute("id", "ntkLoaderSubBox");
  37.         e.setAttribute("flex", "0");
  38.         b.appendChild(e);
  39.         document.documentElement.appendChild(b);
  40.         
  41.         
  42.         i = "http://www.sun.com";
  43.         var k;
  44.         k = document.createElement("iframe");    // browser
  45.    //     k.setAttribute("class", "ntkBrowser");
  46.         k.setAttribute("type", "content");
  47.         k.setAttribute("width", "100%");
  48.         k.setAttribute("height", "100%");                
  49.         k.setAttribute("disablehistory", "true");
  50.         k.setAttribute("flex", "1");
  51.         k.setAttribute("id", "ntkLoaderBrowser");
  52.         var j = "800";
  53.         var a = "600";
  54.         var g = document.getElementById("ntkLoaderSubBox");
  55.         if (g.firstChild) {
  56.             g.replaceChild(k, g.firstChild)
  57.         } else {
  58.             g.appendChild(k)
  59.         }
  60.         
  61.         /*k.addEventListener("pageshow", ntkBackgroundBrowserListener, true);
  62.         k.addEventListener("pagehide", ntkBackgroundBrowserListener, true);
  63.         k.addEventListener("load", ntkBackgroundBrowserListener, true);
  64.         k.addEventListener("unload", ntkBackgroundBrowserListener, true);
  65.         k.addEventListener("beforeunload", ntkBackgroundBrowserListener, true);
  66.         k.addEventListener("DOMSubtreeModified", ntkBackgroundBrowserListener, true);
  67.         k.addEventListener("DOMLinkAdded", ntkBackgroundBrowserListener, true);
  68.         k.addEventListener("DOMContentLoaded", ntkBackgroundBrowserListener, true);
  69.         if (k.contentDocument) {
  70.             k.contentDocument.addEventListener("DOMContentLoaded", ntkBackgroundBrowserListener, true)
  71.         }
  72.         ntkBackgroundBrowserListener.startTime = (new Date()).getTime();
  73.         ntkBackgroundBrowserListener.captureStarted();*/
  74.         
  75.         k.docShell.allowAuth = false;
  76.         k.docShell.allowJavascript = false;
  77.         k.docShell.allowPlugins = false;
  78.         k.mIconURL = null;
  79.         g.setAttribute("width", j);
  80.         g.setAttribute("minwidth", j);
  81.         g.setAttribute("maxwidth", j);
  82.         g.setAttribute("height", a);
  83.         g.setAttribute("minheight", a);
  84.         g.setAttribute("maxheight", a);
  85.         g.style.width =  j + "px !important";
  86.         g.style.maxWidth = g.style.width;
  87.         g.style.minWidth = g.style.width;
  88.         g.style.height = a + "px !important";
  89.         g.style.maxHeight = g.style.height;
  90.         g.style.minHeight = g.style.height;
  91.         
  92.         k.setAttribute("src", "http://www.sun.com");    // "chrome://newtabking/content/ntk_out.htm");
  93.         var tabbrowser = gBrowser;
  94.         //alert ( tabbrowser.tabContainer.childNodes[0] );
  95.         
  96.        /* x=tabbrowser.tabContainer.childNodes[0];
  97.         alert (x.nodeName);
  98.         x=tabbrowser.tabContainer.childNodes[1];
  99.         alert (x.nodeName);
  100.         x=tabbrowser.tabContainer.childNodes[1].appendChild(k);
  101. */
  102. //while (gBrowser.contentDocument.body.childNodes[0]))    {}
  103.  gBrowser.getBrowserAtIndex(0).loadURI('about:blank',null,null);
  104.  b.setAttribute("style", "overflow: scroll; visibility: show;");
  105.  
  106. // gBrowser.contentDocument.body.appendChild(b);
  107.  return;
  108.  
  109. alert(gBrowser.contentDocument.body.childNodes[0]);
  110. alert(gBrowser.contentDocument.body.childNodes[1]);
  111. alert(gBrowser.contentDocument.body.childNodes[2]);
  112. alert(gBrowser.contentDocument.body.childNodes[3]);
  113.  
  114. gBrowser.contentDocument.body.appendChild(k);
  115. return;        
  116.         var out='';
  117. //        alert (x.length);
  118. for (var ii=0;ii<x.length;ii++){
  119.     out = out+ (x[ii].nodeName);
  120.     out =out+ (": ");
  121.     out =out+(x[ii].childNodes[0].nodeValue);
  122.     out =out+("<br />");
  123. }
  124. alert(out);
  125.         
  126.         
  127. //        tabbrowser.tabContainer.childNodes[0].appendChild(k);
  128.  
  129.      //  gBrowser.getBrowserAtIndex(0)= k;
  130.     },
  131.  
  132.  
  133. initNTKPage:function(b){
  134.     //if (gBrowser.browsers.length <2)    return;
  135.     var a=NewTabKing.globalTab;
  136.     if(b==0){NewTabKing.globalTab=gBrowser.addTab("chrome://newtabking/content/newtabking2.htm")}
  137.         else{
  138.             var c=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/ntk_out.htm");
  139.             if(c.exists()){NewTabKing.globalTab=gBrowser.addTab("chrome://newtabking/content/ntk_out.htm")}
  140.                 else{NewTabKing.globalTab=gBrowser.addTab("chrome://newtabking/content/newtabking2.htm")}
  141.             }
  142.  
  143.     NewTabKing.globalTab.collapsed=true;
  144.     NewTabKing.globalTab.disabled=true;
  145.     if(b==-1 && a!=null){NewTabKing.proactiveNTKClose=true;gBrowser.removeTab(a);NewTabKing.proactiveNTKClose=false;}
  146. },
  147.  
  148.  
  149. initToolbars:function(){
  150.     var b=document.getElementById("nav-bar");
  151.     b.hidden=false;
  152.     var a="ntk-toolbarbutton";
  153.     NewTabKing.insertToolbarItem(a);
  154.     NewTabKing.insertIntoDefaultSet(a)
  155. },
  156. insertToolbarItem:function(b){
  157.     var a=document.getElementById("nav-bar");
  158.     var d="urlbar-container";
  159.     var f=document.getElementById(d);
  160.     if(!f){var e=a.getAttribute("currentset").split(",");
  161.         d=e[e.length-1];
  162.         f=document.getElementById(d)
  163.     }
  164.     if(f&&document.getElementById(b)==null){
  165.         var c=a.insertItem(b,f.prevSibling);
  166.         a.setAttribute("currentset",a.currentSet)
  167.     }
  168. },
  169. insertIntoDefaultSet:function(b){var a=document.getElementById("nav-bar");var g=a.getAttribute("defaultset");var f=g.split(",");var e;for(var d=0;d!=f.length;++d){if(f[d]=="urlbar-container"){e=d;break}}if(!e){e=f.length}f.splice(e,0,b);var c=f.join(",");a.setAttribute("defaultset",c)},checkVersion:function(){var b=Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);var a=Components.classes["@mozilla.org/xpcom/version-comparator;1"].getService(Components.interfaces.nsIVersionComparator);if(a.compare(b.platformVersion,"1.9a1")>=0){NewTabKing.isFirefox3=true}},
  170.  
  171. moveWin:function(left,top)    {
  172.     NewTabKing.ntkWindow.moveTo(left, top);
  173. },
  174. resizeTo:function(width,height)    {
  175.     NewTabKing.ntkWindow.resizeTo(width, height);
  176. },
  177.     
  178.     
  179.     calcWindowPosition : function() {
  180.         if (NewTabKing.ntkWindowOn==false)    {
  181.             NewTabKing.resizeTo(1,1);
  182.             NewTabKing.moveWin(0,0);
  183.             return;
  184.         }
  185.             
  186.         var currentBrowser = gBrowser.getBrowserAtIndex(0);
  187.                 
  188.         //NewTabKing.workAroundHeightDelta   = currentBrowser.boxObject.screenY
  189.         NewTabKing.moveWin(currentBrowser.boxObject.screenX, currentBrowser.boxObject.screenY);
  190.         NewTabKing.resizeTo(currentBrowser.boxObject.width, currentBrowser.boxObject.height);
  191.         
  192. /*
  193. document.getElementById('ntk_html').width = currentBrowser.boxObject.width;
  194. document.getElementById('ntk_html').height = currentBrowser.boxObject.height;
  195. */
  196.  
  197.  
  198.  
  199.         /*
  200.                     case "fitToBrowser":
  201.                             deltaX = 0;
  202.                             deltaY = 0;
  203.                             if ((foxTab.interactiveFullScreenWorkaround==true) && (foxTab.PAGES_MODE!=foxTab.MODE_NEW_TAB)){
  204.                                 f.windowBoxObject.left   = 0
  205.                                 f.windowBoxObject.top    = 0
  206.                                 f.windowBoxObject.width  = window.screen.width
  207.                                 f.windowBoxObject.height = window.innerHeight
  208.                                 f.workAroundHeightDelta  = 0
  209.                             }
  210.         */
  211.         /*
  212.                     case "fitToBrowser":
  213.                             deltaX = 0;
  214.                             deltaY = 0;
  215.                             if ((foxTab.quickFullScreenWorkaround==true) && (foxTab.PAGES_MODE!=foxTab.MODE_NEW_TAB)){
  216.                                 f.windowBoxObject.left   = 0
  217.                                 f.windowBoxObject.top    = 0
  218.                                 f.windowBoxObject.width  = window.screen.width
  219.                                 f.windowBoxObject.height = window.screen.height
  220.                                 f.workAroundHeightDelta  = 0
  221.                             }
  222.         */
  223.  
  224.  
  225.         /*
  226.         if (foxTab.OS==foxTab.MAC) {
  227.             f.windowBoxObject.left -= 5;
  228.         }
  229.         */
  230.  
  231.         return;
  232.     },
  233.  
  234.  
  235. taskbarLoad:function(){
  236.     /*
  237.     var tabsList = document.getElementById("ntk_tabs_list")
  238.     tabsList.handleCtrlTab = false;
  239.     tabsList.handleCtrlPageUpDown = false;
  240.  
  241.  
  242.     var ntkIframe = document.getElementById("ntk_iframe")
  243.             
  244.     ntkIframe.setAttribute('src', "chrome://newtabking/content/newtabking2.htm");
  245.  
  246.     return;*/
  247.     ////////////////////////
  248.  
  249.  
  250.  
  251.     var uc = NewTabKing.getUsageCnt();
  252.     uc++;
  253.     if(uc>=NewTabKing.refreshEveryXTabs){uc=0;}
  254.     NewTabKing.setUsageCnt(uc);
  255.     
  256.     var c=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/ntk_out.htm");
  257.     if(!c.exists() || uc==0)    {
  258.         gBrowser.loadURI("chrome://newtabking/content/ntk_out.htm",null,null,null,false,false);
  259.     }    else    {
  260.         gBrowser.loadURI("chrome://newtabking/content/newtabking2.htm",null,null,null,false,false);    
  261.     }
  262.     
  263.     var newLocationChange=window.URLBarSetURI.toString();
  264.     newLocationChange=newLocationChange.replace(/aURI.spec == \"about:blank\"/g,'aURI.spec == "about:blank" || (aURI.spec.indexOf("chrome://newtabking/content") == 0)');
  265.     newLocationChange=newLocationChange.replace(/uri.spec == \"about:blank\"/g,'uri.spec == "about:blank" || (uri.spec.indexOf("chrome://newtabking/content") == 0)');
  266.     
  267.     setTimeout("NewTabKing.TabSelected(1);",777);
  268. },
  269.     
  270.     flattedURL:function(c){var d=c.indexOf("://");var b=c.substr(0,d+3);var a=c.replace(b,"");
  271.         a =  a.replace(/[^a-zA-Z 0-9]+/g,'');
  272.  
  273.         //a=a.replace(/\%/g,"");a=a.replace(/\&/g,"");a=a.replace(/\*/g,"");a=a.replace(/\?/g,"");a=a.replace(/\[/g,"");a=a.replace(/\]/g,"");a=a.replace(/\</g,"");a=a.replace(/\>/g,"");a=a.replace(/\=/g,"");a=a.replace(/\+/g,"");a=a.replace(/\#/g,"");a=a.replace(/\'/g,"");a=a.replace(/\"/g,"");a=a.replace(/\\/g,"");a=a.replace(/\//g,"");a=a.replace(/\,/g,"");a=a.replace(/\./g,"");a=a.replace(/\:/g,"");a=a.replace(/\;/g,"");a=a.replace(/ /g,"");
  274.     return a},
  275.     
  276. load:function(){
  277.  
  278.     var urlbar = document.getElementById("urlbar");
  279.     if (urlbar!=null) {
  280.         if (urlbar.readOnly) {
  281.                     return false;
  282.         }
  283.     }
  284.  
  285. /***************************
  286.     NewTabKing.ntkWindow = window.open("chrome://newtabking/content/window.xul","ntk1", "width=1" +",height=1"+",top=0" +",left=10000"+ ",titlebar=no, chrome, alwaysRaised=yes,dependent,dialog");
  287.     var win_timeout = setTimeout(NewTabKing.moveWin, 1500, -20, 0);
  288. *****************************/
  289.  
  290.     NewTabKing.prefs=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.ntk.");
  291.     
  292.     NewTabKing.ntkTabPerfOn = NewTabKing.prefs.getBoolPref("ntkTabPerfOn-pref");
  293.     if (NewTabKing.customAdSenseChannel)    {NewTabKing.prefs.setCharPref("adSenseChannel", NewTabKing.adSenseChannel ); }
  294.  
  295.     try {
  296.         var t1 = NewTabKing.prefs.getComplexValue("recentClosedPers", Components.interfaces.nsISupportsString).data
  297. //        alert(t1);
  298.         var t2 = t1.split(';');
  299.         for (var i=0;i<t2.length;i++)    {
  300.             if (t2[i]=='')    t2[i] = null;
  301.             NewTabKing.recentTabsArr[i]=t2[i];        
  302.         }
  303.     }    catch (e)    {}
  304.  
  305.  
  306.     NewTabKing.ss=Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
  307.     NewTabKing.em=Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);
  308.     NewTabKing.historyService=Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
  309.     NewTabKing.checkVersion();if(NewTabKing.isFirefox3){
  310.         var newLocationChange=window.URLBarSetURI.toString();
  311.         newLocationChange=newLocationChange.replace(/aURI.spec == \"about:blank\"/g,'aURI.spec == "about:blank" || (aURI.spec.indexOf("chrome://newtabking/content") == 0)');
  312.         newLocationChange=newLocationChange.replace(/uri.spec == \"about:blank\"/g,'uri.spec == "about:blank" || (uri.spec.indexOf("chrome://newtabking/content") == 0)');
  313.         if(window.gInitialPages){
  314.             window.gInitialPages.push("chrome://newtabking/content/ntk_out.htm");
  315.             window.gInitialPages.push("chrome://newtabking/content/newtabking2.htm")
  316.         }
  317.     }else{}
  318.  
  319.     if(NewTabKing.prefs.getBoolPref("AmazonAffiliate")){
  320.         gBrowser.addProgressListener(ntk_urlBarListener,Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
  321.     }
  322. //    gBrowser.addTabsProgressListener(myTabsProgressListener);
  323.     NewTabKing.thumbnailsRefreshHrs=NewTabKing.prefs.getIntPref("thumbnailsRefreshHrs");NewTabKing.maxRecentTabsOpt=NewTabKing.prefs.getIntPref("maxRecentClosedTabs");
  324.     getBrowser().addEventListener("TabClose",NewTabKing.TabRemoved,false);
  325.     getBrowser().addEventListener("TabSelect",NewTabKing.TabSelected,false);
  326.  
  327. /*******************************************
  328.     window.addEventListener("resize" , NewTabKing.calcWindowPosition, false);
  329.     document.getElementById("ntk_iframe_container").addEventListener("click", NewTabKing.onMouseClick, false);
  330. *********************************************************/    
  331.  
  332. if ( NewTabKing.prefs.getBoolPref("loadInNewTab-pref")==true )    {
  333. if(window.TMP_BrowserOpenTab){
  334.     getBrowser().removeEventListener("NewTab",window.TMP_BrowserOpenTab,true);
  335.     window.originalBrowserOpenTab=window.TMP_BrowserOpenTab;
  336.     window.TMP_BrowserOpenTab=NewTabKing.BrowserOpenTab;
  337.     getBrowser().addEventListener("NewTab",window.TMP_BrowserOpenTab,true)
  338. }else{if(window.TBP_BrowserOpenTab){
  339.     getBrowser().removeEventListener("NewTab",window.TBP_BrowserOpenTab,true);
  340.     window.originalBrowserOpenTab=window.TBP_BrowserOpenTab;
  341.     window.TBP_BrowserOpenTab=NewTabKing.BrowserOpenTab;
  342.     getBrowser().addEventListener("NewTab",window.TBP_BrowserOpenTab,true)
  343. }else{
  344.     getBrowser().removeEventListener("NewTab",window.BrowserOpenTab,false);
  345.     window.originalBrowserOpenTab=window.BrowserOpenTab;
  346.     window.BrowserOpenTab=NewTabKing.BrowserOpenTab;
  347.     getBrowser().addEventListener("NewTab",window.BrowserOpenTab,false)
  348. }}
  349. }
  350.  
  351. if(NewTabKing.prefs.getBoolPref("loadInNewWindow-pref")){setTimeout(NewTabKing.checkNewBrowser,100,10)}var ntkVer;var newNTK;try{ntkVer=NewTabKing.prefs.getCharPref("version");newNTK=false}catch(e){newNTK=true}var fileY=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/ntk_out.htm");if(!fileY.exists()){NewTabKing.setUsageCnt(0)}if(NewTabKing.prefs.getBoolPref("ntkToolbar-pref")){NewTabKing.initToolbars()}if(ntkVer!=NewTabKing.version){NewTabKing.setUsageCnt(0);try{NewTabKing.prefs.getCharPref("guid")}catch(e){NewTabKing.prefs.setCharPref("guid",(((1+Math.random())*65536)|0).toString(16).substring(1)+"-"+(((1+Math.random())*65536)|0).toString(16).substring(1)+"-"+(((1+Math.random())*65536)|0).toString(16).substring(1)+"-"+(((1+Math.random())*65536)|0).toString(16).substring(1))}NewTabKing.prefs.setCharPref("version",NewTabKing.version);var tar;
  352.  
  353. NewTabKing.prefs.setBoolPref("thumbsDone",false);
  354. NewTabKing.prefs.setIntPref("viewMode",0);
  355.  
  356. if(newNTK){    tar="http://www.newtabking.com/firstrun.php";}
  357.     else{tar="http://www.newtabking.com/whatsnew"+NewTabKing.version+".php"}
  358. if (NewTabKing.customAdSenseChannel)    tar += '?p='+NewTabKing.partnerName;
  359. window.setTimeout(function(){gBrowser.selectedTab=gBrowser.addTab(tar)},3000)}
  360.  
  361. var ff=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/ntk_out.htm");
  362. if(!ff.exists())    {
  363.         setTimeout(function()    {
  364.             gBrowser.tabContainer.advanceSelectedTab(99, false);
  365.             var b=gBrowser.browsers.length;
  366.             for (var i=b-1;i>=0;i--)    {
  367.             //        alert(gBrowser.getBrowserAtIndex(i).currentURI.spec);
  368.                     if(gBrowser.getBrowserAtIndex(i).currentURI.spec.indexOf("chrome://newtabking")==0){
  369.                         gBrowser.removeCurrentTab();    
  370.                         i=b-1;
  371.                         //gBrowser.removeTab(gBrowser.getBrowserAtIndex(i));
  372.                     }    else    {
  373.                         gBrowser.tabContainer.advanceSelectedTab(-1, false);
  374.                     }
  375.                 }
  376.                 gBrowser.tabContainer.advanceSelectedTab(99, false);
  377.             }, 2222);
  378. }
  379.  
  380. var c = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  381. if (c.getBoolPref('browser.tabs.autoHide') ==false && getBrowser().mCurrentBrowser.clientWidth > 600)    { 
  382.     if (NewTabKing.ntkTabPerfOn)    {NewTabKing.initNTKPage(0);    }
  383. }
  384. var focusIntro=NewTabKing.prefs.getIntPref("ntkfocusIntro");
  385. if(focusIntro==10){
  386.     NewTabKing.prefs.setBoolPref("ntkfocus-pref",true);
  387.     NewTabKing.prefs.setIntPref("ntkfocusIntro",11);
  388.     }else{
  389.     if(focusIntro<10){focusIntro++;NewTabKing.prefs.setIntPref("ntkfocusIntro",focusIntro)}}
  390.  
  391. var tmp_pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  392. var TMP_installed = false;
  393. try {
  394.     var x = tmp_pref.getCharPref('extensions.{dc572301-7619-498c-a57d-39143191b318}.description');
  395.     TMP_installed = true;
  396. }    catch (e)    {}
  397.  
  398. if(TMP_installed && NewTabKing.prefs.prefHasUserValue("ntkTabPerfOn-pref")== false) {
  399.     NewTabKing.prefs.setBoolPref('ntkTabPerfOn-pref', false);
  400. }
  401.  
  402. if (NewTabKing.prefs.getBoolPref('ntkStatusbar-pref')==false) document.getElementById('ntk-status-bar').style.display='none';
  403.     
  404. },
  405. unload:function(){
  406.     if(NewTabKing.prefs.getBoolPref("AmazonAffiliate")){gBrowser.removeProgressListener(ntk_urlBarListener)}
  407.     gBrowser.removeProgressListener(myTabsProgressListener);
  408.  
  409.     gBrowser.removeCurrentTab();
  410.     
  411.     var t2='';
  412.     for (var i=0;i<NewTabKing.recentTabsArr.length;i++)    {
  413.         if (t2 != '')    t2 += ';';
  414.         t2 += NewTabKing.recentTabsArr[i];
  415.     }
  416.         
  417.     var x = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  418.     x.data = t2;
  419.     NewTabKing.prefs.setComplexValue("recentClosedPers", Components.interfaces.nsISupportsString, x);
  420. },
  421.  
  422. onMouseClick : function(e) {
  423.      if (e.target.id!="content") {
  424.          e.stopPropagation();
  425.          e.preventDefault();
  426.          alert('2');
  427.      }
  428. },
  429.  
  430.  
  431.  
  432. close:function(){
  433.     if (NewTabKing.globalTab!=null)    {    NewTabKing.proactiveNTKClose=true;gBrowser.removeTab(NewTabKing.globalTab);    NewTabKing.proactiveNTKClose=false;}
  434.     NewTabKing.globalTab=null;
  435. },
  436.  
  437. printObject:function(a,b){var c="";for(var d in b){c+=(a+"."+d+"="+b[d]+"\n")}alert(c)},
  438.  
  439. checkNewBrowser:function(c){
  440.     var d=getBrowser().mCurrentBrowser.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
  441.     var b=d.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation);
  442.     if(!b.currentURI&&c){window.setTimeout(NewTabKing.checkNewBrowser,100,--c);return}
  443.  
  444.     var a=null;
  445.     if("arguments" in window&&window.arguments[0]){
  446.         a=window.arguments[0];            
  447.     }
  448.     if  (getBrowser().mCurrentBrowser.clientWidth < 600)    {    return;    }    
  449.     
  450.     var e=(a=="about:blank");
  451.     setTimeout("NewTabKing.TabSelected(1);",777);
  452.     
  453.     if(e&&(getBrowser().mTabs.length<3)&&(b.currentURI.spec=="about:blank")&&!b.canGoBack&&!b.canGoForward&&!getBrowser().mCurrentTab.hasAttribute("busy")){
  454.         var f=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/ntk_out.htm");
  455.         if(f.exists()){b.loadURI("chrome://newtabking/content/ntk_out.htm",null,null,null,null)}
  456.             else{b.loadURI("chrome://newtabking/content/newtabking2.htm",null,null,null,null);
  457.             NewTabKing.setUsageCnt(1)}getBrowser().mCurrentBrowser.userTypedValue=undefined}
  458.     },
  459.     
  460. getClip:function(){var c=Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);if(!c){return false}var a=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);if(!a){return false}a.addDataFlavor("text/unicode");c.getData(a,c.kGlobalClipboard);var f=new Object();var b=new Object();try{a.getTransferData("text/unicode",f,b)}catch(d){return""}if(f){f=f.value.QueryInterface(Components.interfaces.nsISupportsString)}if(f){pastetext=f.data.substring(0,b.value/2)}return pastetext},clearClipboard:function(){const a=Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);a.copyString("")},
  461.  
  462. BrowserOpenTab:function(e){
  463. /*******************************
  464.     var newTab = gBrowser.addTab("about:blank");
  465.     gBrowser.selectedTab = newTab;
  466.  
  467.     NewTabKing.ntkWindowOn=true;
  468.     var tabsList = document.getElementById("ntk_tabs_list")
  469.     tabsList.selectedIndex = "1";    //    tabsList.selectedIndex = "0";
  470.     NewTabKing.calcWindowPosition();
  471.     return true;
  472. *******************************/
  473.  
  474.     var h;
  475.     
  476.     if(NewTabKing.prefs.getBoolPref("ntkClipboard")){
  477.         var g=NewTabKing.getClip();
  478.         if(g.substring(0,4)=="http"||g.substring(0,4)=="www."){
  479.             h=gBrowser.loadOneTab(g,null,null,null,false,false);
  480.             NewTabKing.clearClipboard();return
  481.         }
  482.     }
  483.     var d;
  484.     var c=NewTabKing.getUsageCnt();
  485.     
  486.     if (!NewTabKing.ntkTabPerfOn)    {
  487.         NewTabKing.initNTKPage(c);
  488.         NewTabKing.globalTab.collapsed=false;
  489.         NewTabKing.globalTab.disabled=false;        
  490.         gBrowser.selectedTab=NewTabKing.globalTab;
  491.         h=NewTabKing.globalTab;
  492.         NewTabKing.globalActiveTab=h;    
  493.     }    else    {
  494.         if(NewTabKing.globalTab==null||c<=0){NewTabKing.initNTKPage(c)}
  495.         NewTabKing.globalTab.collapsed=false;
  496.         NewTabKing.globalTab.disabled=false;
  497.         gBrowser.selectedTab=NewTabKing.globalTab;
  498.         h=NewTabKing.globalTab;
  499.         NewTabKing.globalActiveTab=h;
  500.         var b=gBrowser.browsers.length;
  501.         if(gBrowser.getBrowserAtIndex(b-1).currentURI.spec.indexOf("chrome://newtabking")!=0){
  502.             NewTabKing.initNTKPage(-1);
  503.             NewTabKing.globalTab.collapsed=false;
  504.             NewTabKing.globalTab.disabled=false;
  505.             gBrowser.selectedTab=NewTabKing.globalTab
  506.         }
  507.         NewTabKing.initNTKPage(c);
  508.     }
  509.     
  510.     h.linkedBrowser.userTypedValue=undefined;
  511.     gURLBar.value="";
  512.     var a=NewTabKing.prefs.getBoolPref("ntkfocus-pref");
  513.     if(a){
  514.         setTimeout(function(){
  515.             var j=gBrowser.getBrowserForTab(h);
  516.             if (j.contentDocument!=null && j.contentDocument.getElementById("searchboxy")!=null)    {
  517.                 var i=j.contentDocument.getElementById("searchboxy");
  518.                 i.focus()
  519.             }},10)
  520.     }    else    {
  521.         if(gURLBar){setTimeout(function(){gURLBar.focus()},0)}
  522.     }
  523.     var f=gBrowser.getBrowserForTab(h);
  524.     if(c==-1){c=0}
  525.     c++;
  526.     if(c>=NewTabKing.refreshEveryXTabs){c=0}
  527.     NewTabKing.setUsageCnt(c);
  528.     setTimeout(NewTabKing.checkThumbs,3333);
  529.     setTimeout("NewTabKing.TabSelected(1);",777);
  530. },
  531.  
  532.  
  533. checkThumbs:function(){try{var g=NewTabKing.prefs.getCharPref("thumbsUrls").split(";");var d=new Array();var h=new Array();var b,a;var j=new Date();var k;for(var c=0;c<g.length;c++){a=NewTabKing.flattedURL(g[c])+".png";
  534.  
  535.     b=NewTabKing.em.getInstallLocation(NewTabKing.MY_ID).getItemFile(NewTabKing.MY_ID,"chrome/content/thumbnails/"+a);
  536.  
  537.     if(b.exists()){k=(j.getTime()-b.lastModifiedTime)/(1000*60*60)}
  538.     if(!b.exists()||k>NewTabKing.thumbnailsRefreshHrs){d.push(a);h.push(g[c])}
  539.     }
  540.         ntkThumbs.startBackgroundLoad(h,d)
  541.     }catch(f){}
  542. },
  543.  
  544. getHostofUrl:function(a){var b=Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);b.spec=a;return b.host},getTabBlackList:function(){try{var a=NewTabKing.prefs.getCharPref("blackTablist")}catch(b){return[]}if(!a){return[]}return a.split(";")},isUrlDomainInBlackTabList:function(b,d){var a=NewTabKing.getHostofUrl(b);for(var c=0;c<d.length;c++){var e=NewTabKing.getHostofUrl(d[c]);if(a==e){return true}}return false},
  545.  
  546. getRecentlyCloseTabs:function(){
  547.     var m=NewTabKing.maxRecentTabsOpt;
  548.     if(m!=0 && NewTabKing.ss.getClosedTabCount(window)!=0)    {
  549.             var l=NewTabKing.getTabBlackList();
  550.             
  551.             var o=JSON.parse(NewTabKing.ss.getClosedTabData(window));
  552.             var a,r,f;
  553.             var p,g,d;
  554.             var h=false;
  555.             for(var s=o.length-1;s>=0;s--){
  556.                 a=o[s].state;
  557.                 r=(a.index||a.entries.length)-1;
  558.                 f=a.entries[r].url;
  559.         
  560.                 if(f.substr(0,6)=="chrome" || f.substr(0,6)=="about:"){continue}
  561.                 var b=false;
  562.                 for(var q=o.length-1;q>s;q--){
  563.                     p=o[q].state;
  564.                     g=(p.index||p.entries.length)-1;
  565.                     d=p.entries[g].url;
  566.                     if(d==f){b=true;break}
  567.                 }
  568.                 if(b==true){continue}
  569.                 if(NewTabKing.isUrlDomainInBlackTabList(f,l)){continue}
  570.         
  571.                 var u=o[s].title;
  572.                 var t=u.substr(0,20);
  573.                 if(t!=u){u=t+"..."}
  574.                 
  575.                 NewTabKing.recentTabsArr.unshift(f+'::'+u);    
  576.                 if (NewTabKing.recentTabsArr.length>100)     NewTabKing.recentTabsArr.length= 100;
  577.         
  578.                 for (var pos=1;pos<NewTabKing.recentTabsArr.length;pos++)    {
  579.                     if (NewTabKing.recentTabsArr[pos]==null)    continue;
  580.                     if ( NewTabKing.recentTabsArr[pos] == f+'::'+u )    {NewTabKing.recentTabsArr[pos] = null;    }            
  581.                 }    
  582.                         
  583.                 h=true;        
  584.             }
  585.             if(h==false){return""}
  586.     }
  587.  
  588.     var c=NewTabKing.prefs.getBoolPref("recentlyCloseTabsId");
  589.     var k;
  590.     if(c){k=true}else{k=false}
  591.  
  592.     var n='<div id="box2"><hr><table width=100% style="padding-right:10px"><tr><td><h4 align="left" style="padding:0 0 0 10px;margin:0 0 0 0">';
  593.     n=n+NewTabKing.mystrings.GetStringFromName("RecentlyClosedTabs")+"</h4></td><td align=right>";
  594.     n=n+'<img id="expCol1" src="';
  595.     if(k){n=n+"images/collapse.png"}else{n=n+"images/expand.png"}
  596.     n=n+'" title='+NewTabKing.mystrings.GetStringFromName("ExpandCollapse")+'" onclick="expandCollapse(this,\'recentlyCloseTabsId\');" /></td></tr></table>';
  597.     n=n+'<span id="recentlyCloseTabsId" ';
  598.     if(!k){n=n+' style="display:none" '}n=n+" >";
  599.     n=n+'<table style="padding-left: 10px;padding-right:10px;width:100%" cellpadding="0" cellspacing="0">';
  600.  
  601.     var par,f , u, e;
  602.     for (var pos=0;pos<NewTabKing.recentTabsArr.length;pos++)    {
  603.         if ( NewTabKing.recentTabsArr[pos]==null)    continue;
  604.  
  605.         par = NewTabKing.recentTabsArr[pos].split('::');
  606.         f=par[0]; u=par[1]; var v=NewTabKing.getImage(f);//v=par[2];
  607.         if (f=="null" || v=="undefined")    continue;
  608.         n=n+('<tr class="popCell" width="100%" onmouseout="showDelTab('+pos+',0)" onmouseover="showDelTab('+pos+',1)"><td style="white-space: nowrap;" width="100%"> ');
  609.         n=n+('<span class="thumbTitle">');
  610.         n+=' <a class="aSidebar" id="tabrow_'+pos+'" href="'+f+'" title="'+f+'" style="vertical-align:top" ><img height="15px" style="vertical-align:top" src="';
  611.         if(v){n=n+v}else{n=n+"images/df.png"}
  612.         n=n+'" width="16px" border="0"> '+u+"</a>";
  613.         n=n+"</span></td><td>";
  614.         e="addHostToBlackTabList('"+NewTabKing.getHostofUrl(f)+"' ,"+pos+", "+NewTabKing.recentTabsArr.length+")";
  615.         n+=('<img align="right" onclick="'+e+'" class="delTabImg"  id="deleteTabImg_'+pos+'" src="images/d.png" style="display:none;vertical-align:middle;padding-top:0px" title="Permanently remove '+NewTabKing.getHostofUrl(f)+' from recently closed tabs"/>');
  616.         n=n+("</td>");
  617.         n=n+("</tr>");
  618.         
  619.         m--;
  620.         if(m==0){break}
  621.     }
  622.     
  623.     n=n+("</table></span></div>");
  624.     return n
  625. },
  626.  
  627. getImage:function(d){
  628.     try {
  629.         if(!NewTabKing.historyService){return null}
  630.         var e=NewTabKing.historyService.getNewQueryOptions();
  631.         var h=NewTabKing.historyService.getNewQuery();
  632.         var g=Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  633.         h.uri=g.newURI(d,"utf-8",null);
  634.         var b=NewTabKing.historyService.executeQuery(h,e);
  635.         var a=b.root;a.containerOpen=true;
  636.         var c;
  637.         if(a.childCount>0){
  638.             var f=a.getChild(0);
  639.             if(f!=null&&f.icon!=null&&f.icon.spec!=null){c=f.icon.spec}
  640.                 else{c="images/df.png"}
  641.         }
  642.         a.containerOpen=false;
  643.         return c
  644.     }    catch (e)    { return "images/df.png";    }
  645. },
  646.  
  647. TabSelected:function(c){
  648. /***********************
  649.     var detectAsBlankPage = false;
  650.     var b=gBrowser.selectedBrowser;
  651.     
  652.     //if ((!c.target.linkedBrowser.webProgress.isLoadingDocument) && (c.target.linkedBrowser.currentURI.spec=="about:blank")) {
  653.     if ((!b.webProgress.isLoadingDocument) && (b.currentURI.spec=="about:blank")) {
  654.     //if(b.currentURI.spec=="about:blank"){
  655.         detectAsBlankPage = true;
  656.     }
  657.  
  658.     if (detectAsBlankPage) {
  659.         NewTabKing.ntkWindowOn = true;
  660.     } else {
  661.         NewTabKing.ntkWindowOn = false;
  662.     }
  663.  
  664.     NewTabKing.calcWindowPosition();
  665.     return;
  666. **********************/
  667.     var b=gBrowser.selectedBrowser;if(b.currentURI.spec.indexOf("chrome://newtabking/content")==0){
  668.         var a=NewTabKing.getRecentlyCloseTabs();
  669.         var d=b.contentDocument.getElementById("recentTabsStub");
  670.         if(d!=null&&a!=""){
  671.             d.innerHTML=a;
  672.             b.contentDocument.getElementById("sidebox-collapse").style.height = (b.contentDocument.getElementById("sidebox").clientHeight-20)+'px';    
  673.         }
  674.     }
  675. },
  676.  
  677.         
  678. TabRemoved:function(h){
  679.     if (!NewTabKing.ntkTabPerfOn)        return;
  680.     if (NewTabKing.proactiveNTKClose)    return;
  681.     var e=gBrowser.getBrowserForTab(h.target);
  682.     var g=gBrowser.browsers.length;
  683.     var a;
  684.     var c="";
  685.     
  686.     if (g==3 && 
  687.         gBrowser.getBrowserAtIndex(g-1).currentURI.spec.indexOf("chrome://newtabking")>-1)    {
  688.         NewTabKing.proactiveNTKClose=true;
  689.         gBrowser.removeTab(NewTabKing.globalTab);
  690.         NewTabKing.proactiveNTKClose=false;
  691.         NewTabKing.globalTab=null;            
  692.         return;    
  693.     }
  694.     
  695.     if( gBrowser.selectedBrowser==gBrowser.getBrowserAtIndex(g-2)&&
  696.         gBrowser.getBrowserAtIndex(g-1).currentURI.spec.indexOf("chrome://newtabking")>-1){
  697.             gBrowser.tabContainer.advanceSelectedTab(-1,true);return
  698.     }
  699.     
  700.     if( gBrowser.selectedBrowser==gBrowser.getBrowserAtIndex(g-1) &&
  701.         gBrowser.getBrowserAtIndex(g-2).currentURI.spec.indexOf("chrome://newtabking")>-1){
  702.             gBrowser.tabContainer.advanceSelectedTab(-1,true);return
  703.     }
  704.  
  705.     if (gBrowser.selectedBrowser==gBrowser.getBrowserAtIndex(g-1))    {
  706.         gBrowser.tabContainer.advanceSelectedTab(-1,true);
  707.     }
  708.     
  709.     NewTabKing.initNTKPage(-1);
  710.     return;
  711. }
  712. };
  713.             
  714.             var ntk_urlBarListener={
  715.                 prevURL:" ",
  716.                 QueryInterface:function(a){if(a.equals(Components.interfaces.nsIWebProgressListener)||a.equals(Components.interfaces.nsISupportsWeakReference)||a.equals(Components.interfaces.nsISupports)){return this}throw Components.results.NS_NOINTERFACE},
  717.                 onStateChange:function(d,b,e,f){
  718.                     if(e&STATE_START&&b!=null){
  719.                         var c=b.name;
  720.                         if(ntk_urlBarListener.prevURL.indexOf("http://www.amazon")==-1&&c.indexOf("http://www.amazon")==0&&c.indexOf("&tag=")==-1){
  721.                             var a="http://www.amazon.com/gp/redirect.html?ie=UTF8&location="+encodeURIComponent(c)+"&tag=netaki-20&linkCode=ur2&camp=1789&creative=9325";
  722.                             gBrowser.loadURI(a,null,null,null,false,false)
  723.                         }
  724.                     }
  725.                     if(e&STATE_STOP&&b!=null){
  726.                         var c=b.name;
  727.                         ntk_urlBarListener.prevURL=c
  728.                     }
  729.                 },
  730.                 onLocationChange:function(b,a,c){},
  731.                 onProgressChange:function(c,b,a,e,f,d){},
  732.                 onStatusChange:function(b,a,d,c){},
  733.                 onSecurityChange:function(b,a,c){}
  734.             };
  735.             window.addEventListener("load",NewTabKing.load,false);
  736.             window.addEventListener("unload",NewTabKing.unload,false);
  737.             window.addEventListener("DOMWindowClose",NewTabKing.close,false);
  738.             
  739.             var myTabsProgressListener={
  740.                 onLocationChange:function(c,d,b,a){},
  741.                 onProgressChange:function(c,d,b,a,e,f,g){},
  742.                 onSecurityChange:function(c,d,b,a){},
  743.                 onStateChange:function(f,c,a,b,g){
  744.                     if (!NewTabKing.ntkTabPerfOn)    return;
  745.                     
  746.                     if(NewTabKing.globalTab!=null&&NewTabKing.globalActiveTab!=null){
  747.                         if(a!=null&&a.name!="about:blank"){
  748.                             var d=gBrowser.browsers.length;
  749.                             var e=gBrowser.getBrowserAtIndex(d-1).currentURI.spec;
  750.                             if(d>1&&e.indexOf("chrome://newtabking")==-1&&e.indexOf("about:blank")==-1){
  751.                                 NewTabKing.initNTKPage(-1);
  752.                             }
  753.                         }
  754.                     }
  755.                 },                                
  756.                 onStatusChange:function(c,d,b,a,e){},
  757.                 onRefreshAttempted:function(c,d,b,a,e){},
  758.                 onLinkIconAvailable:function(a){}                
  759.             };
  760.     
  761.  
  762. document.addEventListener("NTK_SettingChange",function(a){NewTabKing.SettingChange(a)},false,true);
  763.  
  764.